16. LEFT and RIGHT JOIN
SOLUTION:
- A **LEFT JOIN** and **RIGHT JOIN** do the same thing if we change the tables that are in the **FROM** and **JOIN** statements.
- A **LEFT JOIN** will **at least** return all the rows that are in an **INNER JOIN**.
- **JOIN** and **INNER JOIN** are the same.
- A **LEFT OUTER JOIN** is the same as **LEFT JOIN**.
Above are two small tables for you to test your knowledge of JOINs. You can click on the image to get a better view.
Country has 6 rows and 2 columns:
- countryid and countryName
State has 6 rows and 3 columns:
stateid, countryid, and stateName
Use the above tables to determine the solution to the following questions.
QUIZ QUESTION::
Match each statement to the item it describes.
ANSWER CHOICES:
Description |
Item |
---|---|
State.stateName |
|
State.stateid |
|
Country.countryid |
|
Country.countryName |
|
State.countryid |
SOLUTION:
Description |
Item |
---|---|
State.stateid |
|
Country.countryid |
|
State.countryid |
The above two tables are given again just for minimizing scrolling. If you were to perform the following query:
SELECT c.countryid, c.countryName, s.stateName
FROM Country c
JOIN State s
ON c.countryid = s.countryid;
QUIZ QUESTION::
Match the results of the query to the description.
ANSWER CHOICES:
Description |
Result |
---|---|
3 |
|
2 |
|
6 |
|
7 |
|
8 |
|
12 |
|
0 |
|
1 |
|
4 |
|
5 |
SOLUTION:
Description |
Result |
---|---|
3 |
|
2 |
|
6 |
|
0 |
The above two tables are given again just for minimizing scrolling. If you were to perform the following query:
SELECT c.countryid, c.countryName, s.stateName
FROM Country c
LEFT JOIN State s
ON c.countryid = s.countryid;
QUIZ QUESTION::
Match the results of the query to the description.
ANSWER CHOICES:
Description |
Results |
---|---|
1 |
|
3 |
|
5 |
|
6 |
|
7 |
|
9 |
|
0 |
|
10 |
|
8 |
|
4 |
|
2 |
SOLUTION:
Description |
Results |
---|---|
1 |
|
3 |
|
8 |
|
2 |